package cn.marinda.listener;

import cn.marinda.gui.AbstractHelper;
import cn.marinda.gui.AbstractServerDialog;
import cn.marinda.gui.impl.DownloadServerDiaLogImpl;
import cn.marinda.gui.impl.ServerConsoleHelperImpl;
import cn.marinda.gui.impl.SuccessCreateServerDialogImpl;
import cn.marinda.util.SwingUtils;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 打开服务器控制台点击事件
 *
 * @author hwj
 * @date 2022/07/27
 */
public class OpenServerConsoleActivityEvent implements ActionListener {

    private AbstractServerDialog dialog;
    private AbstractHelper helper = null;
    public OpenServerConsoleActivityEvent(AbstractServerDialog serverDialog){
        this.dialog = serverDialog;
    }

    public OpenServerConsoleActivityEvent(AbstractServerDialog serverDialog,AbstractHelper helper){
        this.dialog = serverDialog;
        this.helper = helper;
    }
    /**
     * Invoked when an action occurs.
     *
     * @param e
     */
    @Override
    public void actionPerformed(ActionEvent e) {
//        关闭完成dialog
        dialog.close();
        if(helper == null){
            show();
            return;
        }
        helper.close();
        show();
        return;

    }

    private void show(){
        ServerConsoleHelperImpl.instance.close();
        ServerConsoleHelperImpl.instance.open();
    }
}
